<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      div {
        width: 400px;
        height: 200px;

        border: 1px solid lightgray;
      }
    </style>
  </head>
  <body>
    <div ondrop="dropHandler(event)" ondragover="dragoverHandler(event)"></div>
    <img
      id="img"
      src="https://www.w3schools.com/html/img_logo.gif"
      alt="log"
      draggable="true"
      ondragstart="dragstartHandler(event)"
    />
    <div ondrop="dropHandler(event)" ondragover="dragoverHandler(event)"></div>

    <script>
      function dropHandler(e) {
        e.preventDefault();
        const data = e.dataTransfer.getData("text");
        e.target.appendChild(document.getElementById(data));
      }

      function dragoverHandler(e) {
        e.preventDefault();
      }

      function dragstartHandler(e) {
        e.dataTransfer.setData("text", e.target.id);
      }
    </script>
  </body>
</html>
